﻿<!DOCTYPE html>
<html>
<!-- 安全活动里程碑 -->

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
        <script src="/static/js/common.js"></script>

</head>

<body>
    <div id="app" class="popupW50" v-cloak>
        <el-form label-position="right" :model="Form" status-icon :rules="rules" ref="ruleForm" label-width="100px"
            size="mini">
            <el-row>
                <el-col :span="24">
                    <div class="elst-select-mini">
                        <el-form-item prop="attachment">

                            <label for="Trainingtime" class="el-form-item__label"
                                   style="width: 150px;">{{HistoricalinquiriesonminutesofSecurityCommitteemeetings.file+mark.m}}</label>

                            <span>
                                <btn-uploadfile-input v-model="Form.attachmentName" text="上传"
                                                      :fileid="Form.attachmentId" :filename="Form.attachmentName" :showdownload="true"
                                                      @success="attachmentHandle"></btn-uploadfile-input>

                            </span>
                        </el-form-item>
                    </div>

                    <!--上报部门-->
                </el-col>
            </el-row>
            <!--<el-row>
                <el-col :span="11">
                    <el-form-item>
                        <div class="elst-select-mini" style="margin-left: -100px;">
                            <el-input size="mini">
                                <template slot="prepend">
                                    {{SafetyMilestone.uploadTime+mark.m}}
                                </template>
                                <el-date-picker slot="suffix" v-model="Form.uploadTime" type="date" size="mini"
                                    format="yyyy-MM-dd" value-format="yyyy-MM-dd" placeholder="选择日期">
                                </el-date-picker>
                            </el-input>
                        </div>
                    </el-form-item>
                </el-col>
                <el-col :span="11" offset="2">
                    <div class="elst-select-mini">
                        <el-form-item prop="uploadPerson">
                            <el-input type="text" v-model="Form.uploadPerson" autocomplete="off" size="mini">
                                <template slot="prepend">
                                    {{SafetyMilestone.uploadPerson+mark.m}}
                                </template>
                            </el-input>
                        </el-form-item>
                    </div>
                </el-col>
            </el-row>-->
            <el-row type="flex" justify="end">
                <el-form-item>
                    <el-button type="primary" @click="onSubmitForm('ruleForm')">{{col.btnSave}}</el-button>
                    <!--<el-button type="primary" @click="onSubmitForm('ruleForm')">{{col.btnCommit}}</el-button>-->
                    <el-button type="primary" @click="parent.ListItem.dialogVisible=false">{{col.btnBack}}</el-button>
                </el-form-item>
            </el-row>
        </el-form>

    </div>
    <script type="text/javascript">
        var uploadText = "请选择上传文件";
        var app = new Vue({
            el: '#app',
            data: {
                //父业传参
                id: '',
                ListItem: ListItem,
                formInline: {
                    model: { uploadPerson: '' },
                    offset: 0,
                    limit: 10
                },
                //业务表单内容
                Form: {
                    id: guidEmpty,
                    uploadPerson: '',
                    safetyMilestoneID: '',
                  //  attachmentName: uploadText,
                    attachmentId: '',
                    attachmentName: ''
                },
                //表单验证
                rules: {
                }
            },
            methods: {
                attachmentHandle: function (response, fileid, fileName) {

                    console.log('fileid', fileid)
                    console.log('fileName', fileName)

                    this.Form.attachmentId = fileid;
                    this.Form.attachmentName = fileName;

                    console.log(' this.Form.attachmentId', this.Form.attachmentid)
                    console.log(' this.Form.attachmentName', this.Form.attachmentName)

                },
                //解決edge下select bug
                visibleChange: function (isVisible) {
                    visibleChange(isVisible)
                },
                handleRemove: function (file) {
                    console.log(file);
                },
                handlePreview: function (file) {
                    console.log(file.name);
                    window.open(file.url)
                },
                //上传前文件的校验
                beforeupload: function (file) {
                    var testmsg = file.name.substring(file.name.lastIndexOf('.') + 1)
                    //将文件名称赋值到label上
                    this.labelUpload = file.name;
                    const extension = testmsg === 'jpg'
                    const extension2 = testmsg === 'png'
                    const isLt10M = file.size / 1024 / 1024 < 10

                    if (!extension && !extension2) {
                        this.$message({
                            message: '上传文件只能是 jpg、png格式!',
                            type: 'warning'
                        });
                    }
                    if (!isLt10M) {
                        this.$message({
                            message: '上传文件大小不能超过 10MB!',
                            type: 'warning'
                        });
                    }
                    if (extension || extension2 && isLt10M)
                        submitUpload(this, 'upload')
                    return extension || extension2 && isLt10M
                },
                //上传附件文件的校验
                fileAttachmentUploadbeforeupload: function (file) {
                    var testmsg = file.name.substring(file.name.lastIndexOf('.') + 1)
                    //将附件名赋值到label上
                    this.Form.attachmentName = file.name;
                    const extension = testmsg === 'rar'
                    const extension2 = testmsg === 'zip'
                    const isLt10M = file.size / 1024 / 1024 < 10
                    if (!extension && !extension2) {
                        this.$message({
                            message: '上传文件只能是 rar、zip格式!',
                            type: 'warning'
                        });
                    }
                    if (!isLt10M) {
                        this.$message({
                            message: '上传文件大小不能超过 10MB!',
                            type: 'warning'
                        });
                    }
                    if (extension || extension2 && isLt10M)
                        submitUpload(this, 'upload')
                    return extension || extension2 && isLt10M
                },
                btnAttachmentUpload: function () {
                    //若更换文件则将文件名字更换触发条件--先删除上一个文件,后添加一个文件
                    if (this.fileAttachmentUpload != uploadText) {
                        this.$refs.Attachmentupload.clearFiles();
                        this.fileAttachmentUpload = file.name;
                    }
                    else {

                    }
                    this.$refs.Attachmentupload.submit();
                },
                onSubmitForm: function (formName) {
                    var mythis = this;
                    this.$refs[formName].validate(function (valid) {
                        //验证通过
                        if (valid) {
                            onSubmitForm(this, '/api/ZB_SafetyMilestoneFile/Save', mythis.Form);
                        } else {
                            //验证失败
                            return false;
                        }
                    });
                },
                getData: function () {
                    getData(this, '/api/SafetyMilestone/get?id=' + this.id);
                },
            },
            mounted: function () {
              
                this.id = getUrlParam("id");
                this.Form.SafetyMilestoneID = this.id;
              //  this.getData();
              
            }
        });
    </script>
</body>

</html>